<template>
  <mu-row style="width: 100%" class="bdtso">
    <mu-data-table style="width: 100%" @select-change="updates" selectable
                   select-all :selects.sync="selects" checkbox :columns="columns" :data="list">
      <div slot="th">请选择</div>
      <template slot-scope="scope">
        <td>{{scope.row.value}}</td>
        <!--        <td class="is-right">{{scope.row.id}}</td>-->
      </template>
    </mu-data-table>
  </mu-row>
</template>

<script>
import api from '@/assets/js/api'

export default {
  name: 'list',
  props: {
    val: '',
    entityName: '',
    multi: ''
  },
  data () {
    return {
      selects: [],
      columns: ['val'],
      list: []
    }
  },
  methods: {
    getData () {
      let _this = this
      api.post('/admin/' + _this.entityName + '/choice', {}, function (res) {
        if (res.s*1 === 1) {
          _this.list = res.d
          //获取原来的数值
          _this.list.map(function (data, index) {
            for (let i in _this.val) {
              if (data.id === _this.val[i]) {
                _this.selects.push(index)
              }
            }
          })
        }
      })
    },
    updates (index, selects) {
      let _this = this
      let data = []
      console.log(selects)
      console.log(index)
      this.selects.map(function (d) {
        data.push(_this.list[d].id)
      })
      console.log(data)
      this.$emit('change', data)
    }
  },
  created () {
  },
  mounted () {
    this.getData()
  },
  watch: {
    selects () {
      this.updates()
    }
  }
}
</script>

<style scoped>

</style>
